package com.huika.dealontop.control.base.extend;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.GridView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.BaseFra;

/**
 * Author: Victor Wu
 * Email: victor-wu*foxmail.com
 * Time: 2015/11/13 11:05
 * Description: TODO
 */
public abstract class BaseActionBarFragment extends BaseFra {

    private ViewGroup mRootView;

    private FrameLayout mContentView;

    private ActionBarHelper mActionBarHelper;

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
        //确保只有唯一的一个父亲
        if (mRootView != null) {
            ViewGroup parent = (ViewGroup) mRootView.getParent();
            if (parent != null) {
                parent.removeView(mRootView);
            }
            //返回原有的布局对象  不往下走了
            return mRootView;
        }

        // Inflate the layout for this fragment
        mRootView = (ViewGroup) inflater.inflate(R.layout.activity_action_bar, container, false);

        assignViews(mRootView);

        mContentView.addView(onCreateContentView(container, bundle));

        initActionBar();

        return mRootView;
    }

    private void assignViews(ViewGroup mRootView) {
        mContentView = (FrameLayout) mRootView.findViewById(R.id.content_area);
    }

    protected void initActionBar() {

    }

    protected ActionBarHelper getActionBarHelper() {
        if (mActionBarHelper == null) {
            mActionBarHelper = new ActionBarHelper(mRootView);
        }
        return mActionBarHelper;
    }

    protected abstract View onCreateContentView(ViewGroup container, Bundle bundle);

}
